﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySQL.Db;
using MySql.Data.MySqlClient;

namespace Gollie.Ajax
{
	public class InsertCashClose : AjaxResult
	{
		public InsertCashClose() : base(null) { }

		public InsertCashClose(AjaxArg arg)
			: base(arg)
		{
		}

		protected override void Init(AjaxArg ajaxArg)
		{
			InsertCashCloseArg arg = (InsertCashCloseArg)ajaxArg;

			uint uid = Convert.ToUInt32(arg.tokenUser);

			try
			{
				string wwHash = Hash.GetHash(arg.ww);

				Database.Queries.InsertCashClose(uid, wwHash);
			}
			catch (MySqlException mySqlEx)
			{
				this.ErrorCode = mySqlEx.Number;
				this.ErrorMessage = MySqlErrorCodes.GetInstance().GetMessage(mySqlEx);
				logger.Warn("InsertCashClose failed for userid {0}: {1}", arg.tokenUser, this.ErrorMessage);
			}
			catch (Exception e)
			{
				if (this.ErrorCode == 0)
					this.ErrorCode = 99;

				this.ErrorMessage = e.Message;
				logger.Warn("InsertCashClose failed for userid {0}: {1}", arg.tokenUser, this.ErrorMessage);
			}

		}
	}
}